namespace 第二次作业
{
    public partial class Form1 : Form
    {
        Bank bank1 = new Bank();
        Bank bank2 = new Bank();
        Bank bank3 = new Bank();
        ATM atm1 = new ATM();
        ATM atm2 = new ATM();
        ATM atm3 = new ATM();

        List<Account> accounts1 = new List<Account>();
        List<Account> accounts2 = new List<Account>();
        List<Account> accounts3 = new List<Account>();
        List<TrustAccount> trustAccounts1 = new List<TrustAccount>();
        List<TrustAccount> trustAccounts2 = new List<TrustAccount>();
        List<TrustAccount> trustAccounts3 = new List<TrustAccount>();


        public Form1()
        {
            InitializeComponent();
            bank1.id = 01;
            bank2.id = 02;
            bank3.id = 03;
            bank1.name = "中国银行";
            bank2.name = "交通银行";
            bank3.name = "光大银行";
            bank1.Accounts = accounts1;
            bank2.Accounts = accounts2;
            bank3.Accounts = accounts3;
            bank1.TrustAccounts = trustAccounts1;
            bank2.TrustAccounts = trustAccounts2;
            bank3.TrustAccounts = trustAccounts3;
            comboBox1.Items.Add(bank1.name);
            comboBox1.Items.Add(bank2.name);
            comboBox1.Items.Add(bank3.name);

            atm1.id = 01;
            atm2.id = 02;
            atm3.id = 03;
            comboBox2.Items.Add(atm1.id);
            comboBox2.Items.Add(atm2.id);
            comboBox2.Items.Add(atm3.id);

            comboBox3.Items.Add("储蓄卡登录");
            comboBox3.Items.Add("信用卡登录");


        }

        public void button1_Click(object sender, EventArgs e)
        {
            if(bank1.name == comboBox1.Text)
            {
                Form form = new 注册(bank1);
                form.Show();
            }
            if (bank2.name == comboBox1.Text)
            {
                Form form = new 注册(bank2);
                form.Show();
            }
            if (bank3.name == comboBox1.Text)
            {
                Form form = new 注册(bank3);
                form.Show();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool flag = false;
            if (bank1.name == comboBox1.Text)
            {
                if(comboBox3.Text == "储蓄卡登录")
                {
                    foreach (Account account in bank1.Accounts)
                    {
                        if (account.getId() == int.Parse(textBox1.Text)&&account.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new depositcard(account);
                            form.Show();
                        }
                    }
                }
                if (comboBox3.Text == "信用卡登录")
                {
                    foreach (TrustAccount trustaccount in bank1.TrustAccounts)
                    {
                        if (trustaccount.getId() == int.Parse(textBox1.Text) && trustaccount.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new Trustcards(trustaccount);
                            form.Show();
                        }
                    }
                }
            }
            if (bank2.name == comboBox1.Text)
            {
                if (comboBox3.Text == "储蓄卡登录")
                {
                    foreach (Account account in bank1.Accounts)
                    {
                        if (account.getId() == int.Parse(textBox1.Text) && account.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new depositcard(account);
                            form.Show();
                        }
                    }
                }
                if (comboBox3.Text == "信用卡登录")
                {
                    foreach (TrustAccount trustaccount in bank1.TrustAccounts)
                    {
                        if (trustaccount.getId() == int.Parse(textBox1.Text) && trustaccount.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new Trustcards(trustaccount);
                            form.Show();
                        }
                    }
                }
            }
            if (bank3.name == comboBox1.Text)
            {
                if (comboBox3.Text == "储蓄卡登录")
                {
                    foreach (Account account in bank1.Accounts)
                    {
                        if (account.getId() == int.Parse(textBox1.Text) && account.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new depositcard(account);
                            form.Show();
                        }
                    }
                }
                if (comboBox3.Text == "信用卡登录")
                {
                    foreach (TrustAccount trustaccount in bank1.TrustAccounts)
                    {
                        if (trustaccount.getId() == int.Parse(textBox1.Text) && trustaccount.getCode() == textBox2.Text)
                        {
                            flag = true;
                            //打开新页面
                            Form form = new Trustcards(trustaccount);
                            form.Show();
                        }
                    }
                }
            }
            if(flag == false)
            {
                MessageBox.Show("不存在该用户！");
            }
        }
    }
}